﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Classes.sim {
    import Mechanics.GameMechanicInterfaces.*;
    import Mechanics.*;
    import flash.utils.*;
    import Classes.*;
    import Modules.bandits.*;
    import Modules.storage.*;
    import Modules.stats.experiments.*;
    import Mechanics.GameEventMechanics.*;

    public class Requirements {

        public static const REQUIREMENT_COINS:String = "coins";
        public static const REQUIREMENT_CASH:String = "cash";
        public static const REQUIREMENT_XP:String = "xp";
        public static const REQUIREMENT_LEVEL:String = "level";
        public static const REQUIREMENT_POPULATION:String = "population";
        public static const REQUIREMENT_EXPERIMENT:String = "experiment";
        public static const REQUIREMENT_ITEM_STORAGE:String = "itemStorage";
        public static const REQUIREMENT_CREW:String = "crew";
        public static const REQUIREMENT_QUEST_NOT_ACTIVE:String = "questNotActive";
        public static const REQUIREMENT_UPGRADE_ACTIONS:String = "upgrade_actions";
        public static const REQUIREMENT_SPECIAL_BANDITS:String = "special_bandits";
        public static const REQUIREMENT_ROLL_CALL:String = "rollCallActive";

        protected var m_entries:Dictionary;

        public function Requirements(_arg1:XML){
            var _local2:XML;
            var _local3:String;
            var _local4:String;
            this.m_entries = new Dictionary();
            super();
            for each (_local2 in _arg1.requirement) {
                _local3 = String(_local2.@type);
                _local4 = String(_local2.@value);
                this.m_entries[_local3] = _local4;
            };
        }
        public function getRequirementValue(_arg1:String):String{
            return ((this.m_entries.hasOwnProperty(_arg1)) ? this.m_entries[_arg1] : null);
        }
        public function checkRequirements(_arg1:MapResource):Boolean{
            var _local2:String;
            var _local3:Boolean;
            for (_local2 in this.m_entries) {
                _local3 = this.checkRequirement(_local2, this.m_entries[_local2], _arg1);
                if (!_local3){
                    return (false);
                };
            };
            return (true);
        }
        protected function checkRequirement(_arg1:String, _arg2:String, _arg3:MapResource):Boolean{
            var _local4:StorageType;
            var _local5:String;
            var _local6:BaseStorageUnit;
            var _local7:Boolean;
            var _local8:IGameMechanic;
            var _local9:RollCallDataMechanic;
            var _local10:int;
            var _local11:Boolean;
            var _local12:Boolean;
            var _local13:Boolean;
            var _local14:Boolean;
            switch (_arg1){
                case REQUIREMENT_COINS:
                    return ((Global.player.gold >= int(_arg2)));
                case REQUIREMENT_CASH:
                    return ((Global.player.cash >= int(_arg2)));
                case REQUIREMENT_XP:
                    return ((Global.player.xp >= int(_arg2)));
                case REQUIREMENT_LEVEL:
                    return ((Global.player.level >= int(_arg2)));
                case REQUIREMENT_POPULATION:
                    return ((Global.world.citySim.getPopulation() >= int(_arg2)));
                case REQUIREMENT_EXPERIMENT:
                    return (!((Global.experimentManager.getVariant(_arg2) == 0)));
                case REQUIREMENT_ITEM_STORAGE:
                    _local4 = (_arg3 as ItemStorage).getStorageType();
                    _local5 = (_arg3 as ItemStorage).getStorageKey();
                    _local6 = Global.player.storageComponent.getStorageUnit(_local4, _local5);
                    return (((_local6) && ((_local6.size >= int(_arg2)))));
                case REQUIREMENT_CREW:
                    return ((Global.crews.getCrewCountByObject(_arg3) >= int(_arg2)));
                case REQUIREMENT_QUEST_NOT_ACTIVE:
                    if (Global.questManager == null){
                        return (false);
                    };
                    return (!(Global.questManager.isQuestActive(_arg2)));
                case REQUIREMENT_UPGRADE_ACTIONS:
                    return ((_arg3.upgradeActions.getTotal() >= int(_arg2)));
                case REQUIREMENT_SPECIAL_BANDITS:
                    return ((BanditManager.numBanditsCaptured >= int(_arg2)));
                case REQUIREMENT_ROLL_CALL:
                    _local7 = !((_arg2 == "false"));
                    _local8 = MechanicManager.getInstance().getMechanicInstance((_arg3 as IMechanicUser), "rollCall", "all");
                    if (((_local8) && ((_local8 is RollCallDataMechanic)))){
                        _local9 = (_local8 as RollCallDataMechanic);
                        _local10 = Global.experimentManager.getVariant(ExperimentDefinitions.EXPERIMENT_ROLL_CALL);
                        _local11 = (Global.player.level < _local9.requiredLevel);
                        if ((((_local10 > 1)) && (!(_local11)))){
                            _local12 = ((_local9.isActiveObject()) && (_local9.canPerformRollCall()));
                            _local13 = (_local9.getState() == RollCallDataMechanic.STATE_IN_PROGRESS);
                            _local14 = (((_local9.getState() == RollCallDataMechanic.STATE_COMPLETE)) && (!(_local9.hasCollected(Global.player.uid))));
                            return ((((((_local12) || (_local13))) || (_local14)) == _local7));
                        };
                    };
                    return (!(_local7));
                case "peddlerSuccessTimes":
                    return ((Global.peddlerManager.successTimes >= int(_arg2)));
                default:
                    throw (new Error(("Unknown requirement " + _arg1)));
            };
        }
        public function isRequirementTypeDefined(_arg1:String):Boolean{
            if (this.m_entries[_arg1] != null){
                return (true);
            };
            return (false);
        }

    }
}//package Classes.sim 
